<template>
	<view class="" style="padding-bottom: 10px;background-color: rgb(250, 250, 250);height: 100vh;">
		<!-- <view class="titlecont" style="margin-top: 30px;display: flex;flex-direction: row;align-items: center;background-color: rgb(250,250,250);">
			<image src="../../static/dbgoback.png" mode="widthFix" style="width: 20px;height: 20px;position: absolute;left: 10px;"
			 @click="test"></image>
			<view class="" style="font-size: 16px;margin-left: 40%;text-align: center;font-weight: 700;">
				群规则
			</view>
		</view> -->  
		<view class="zjl_header">
			 <!-- <countdown :startTime="startTime" :endTime="enTime" /> -->
			<text style="font-size: 20px;"> {{liveCountdown}}</text>
			<!-- <uni-countdown style="" :show-day="true" :hour="hour" :minute="min" :second="miao"></uni-countdown> -->
			<!-- <view v-if="guize.is_give==0"> -->
			<view>
				 <button style="margin-bottom: 15px;margin-right: 15px;margin-top: 25px;background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);"
				  class="mini-btn" type="warn" size="mini" @click="playgamejifen" v-show="guize.sjinfo.hour==0&&guize.sjinfo.min==0&&guize.sjinfo.sec==0">开通积分红包</button>
				<button style="margin-bottom: 15px;margin-top: 25px;background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);"
				 class="mini-btn" type="warn" size="mini" v-show="guize.sjinfo.hour==0&&guize.sjinfo.min<60&&guize.sjinfo.sec!=0" @click="xufei">续费</button>
			</view>
		<!-- 	<view v-else>
				<button style="margin-bottom: 15px;margin-right: 15px;margin-top: 25px;background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);"
				  class="mini-btn" type="warn" size="mini" @click="mplaygamejifen" v-show="guize.sjinfo.hour==0&&guize.sjinfo.min==0&&guize.sjinfo.sec==0">免费开通积分红包</button>
				<button style="margin-bottom: 15px;margin-top: 25px;background: -webkit-linear-gradient(left, #a00000, #e10004, #a00000);"
				 class="mini-btn" type="warn" size="mini" v-show="guize.sjinfo.hour==0&&guize.sjinfo.min<60&&guize.sjinfo.sec!=0" @click="xufei">续费</button>
			</view> -->
		</view>
		<view class="zjl_hedn">
			<view class="" @click="kefakeqiang">
				<view class="" style="display: flex;flex-direction: column;align-items: center;">
					<view class="" style="width: 80px;height: 80px;background-color: rgb(250,250,250);display: flex;justify-content: center;align-items: center;border-radius: 10px;">
							<image src="../../static/img/jinqiangmailei.png" mode="widthFix" style="width: 50px;height: 50px;"></image>
					</view>
					<text style="padding-top: 20px;">禁抢埋雷</text>
				</view>
			</view>
			<view class=""  @click="jinqiangmailei">
				<view class="" style="display: flex;flex-direction: column;align-items: center;">
				<view class="" style="width: 80px;height: 80px;background-color: rgb(250,250,250);display: flex;justify-content: center;align-items: center;border-radius: 10px;">
						<image src="../../static/img/kefakeqiang.png" mode="widthFix" style="width: 50px;height: 50px;"></image>
				</view>
					<text style="padding-top: 20px;">可发可抢</text>
				</view>
			</view>
			
			<!-- <view class="">
				<view class="" style="display: flex;flex-direction: column;align-items: center;">
					<view class="" style="width: 80px;height: 80px;background-color: rgb(250,250,250);display: flex;justify-content: center;align-items: center;border-radius: 10px;">
							<image src="../../static/img/hongbaomiaoqiang.png" mode="widthFix" style="width: 50px;height: 50px;"></image>
					</view>
					<text style="padding-top: 20px;">红包秒抢</text>
				</view>
			</view> -->
		</view>
		<view style="display: flex;justify-content: center;align-items: center;width: 80%;margin: 50px 10%;color: green;font-weight: bold;">注：群主可点击群员头像上下积分，红包为积分制，不包含零钱红包。</view>
		<view class="" style="text-align: center;">
			仅供娱乐,禁止赌博 
		</view>
	</view>
</template>

<script>
	import countdown from "@/components/cz-countdown/cz-countdown.vue"
	import uniCountdown from '@/components/uni-countdown/uni-countdown.vue'
	export default {
		components: {
			uniCountdown,
			countdown
		},
		data() {
			return {
				 startTime:'2020-01-01 00:00:00',
				 enTime:'2020-02-01 00:00:00',
				hour:0,  
				isshow:true,
				money:"",
				roomid:'',
				guize:[],
				qid:'',
				groupName:'',
				status:'',
				min:'',
				miao:'',
				liveCountdown:''
			}
		},
		onShow() {
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/lz/qyxkinfo',
				method: "POST",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				data:{
					id:this.qid
				},
				success: (res) => {
					console.log("群游戏信息",res)
					this.guize = res.data.data
					this.end_time = res.data.data.end_time
					this.getLiveTimeCount(this.end_time)
					this.hour = res.data.data.sjinfo.hour
					this.min = res.data.data.sjinfo.min
					this.miao = res.data.data.sjinfo.sec
				},
				fail: (err) => {
					console.log(err)
				}
			});
		},
		onLoad(option){
			console.log(option)
			console.log(option.roomid)
			this.roomid= option.roomid
			this.groupName = option.groupName
			this.qid= option.q_id
			this.money=option.money	
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/lz/qyxkinfo',
				method: "POST",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				data:{
					id:this.qid
				},
				success: (res) => {
					console.log("群游戏信息",res)
					this.guize = res.data.data
					this.hour = res.data.data.sjinfo.hour
					this.min = res.data.data.sjinfo.min
					this.miao = res.data.data.sjinfo.sec
				},
				fail: (err) => {
					console.log(err)
				}
			});
			uni.request({
				url: this.G_base + '/api/lz/qgzinfo',
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				data: {
					qid: this.roomid,
				},
				success: res => {
					console.log("群规则信息",res)
					if(res.data.status==200){
						this.status = res.data.data[0].status
					}
				}
			})
		},
		methods: {
			//
			getLiveTimeCount(startTime){
				console.log(startTime)
				if(startTime){
					setInterval(()=>{
						let transedPreTime=startTime.replace(/-/g,'/') //这里转化时间格式为以/分隔形式
						let nowTime = new Date().getTime();
						let preTime = new Date(transedPreTime).getTime()
						let obj = null;
						if(preTime - nowTime > 0){
							let time = (preTime - nowTime) / 1000;
							let day = parseInt(time / (60 * 60 * 24));
							let hou = parseInt(time % (60 * 60 * 24) / 3600);
							let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
							let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
							obj = {
								day: day<10?'0'+day:day,
								hou: hou<10?'0'+hou:hou,
								min: min<10?'0'+min:min,
								sec: sec<10?'0'+sec:sec
							};
							this.liveCountdown=obj.day + '天' + obj.hou + '时' + obj.min + '分' + obj.sec + '秒'
						} else {
							obj = {day:'00',hou:'00',min:'00',sec:'00'};
							this.liveCountdown=obj.day + '天' + obj.hou + '时' + obj.min + '分' + obj.sec + '秒'
							clearInterval(this.liveCountTimes)
						}  
					},1000)
					console.log(this.liveCountdown)
				}
			},
			kefakeqiang(){
				if(this.guize.sjinfo.hour==0&&this.guize.sjinfo.min==0&&this.guize.sjinfo.sec==0){
					uni.showToast({
						title:"请先开通",
						icon:"none"
					})
					return
				}
				if(this.status==2){
					uni.showToast({
						title:"本群为可发可抢群",
						icon:"none"
					})
					return
				}
				uni.navigateTo({
					url:"/pages/gameone?roomid="+this.roomid+'&groupName='+this.groupName+'&qid='+this.qid
				})
			},
			mplaygame(){
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/mfqyxstart',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.qid,
						status:1
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:"开通成功"
							})
							setTimeout(()=>{uni.navigateBack({
								delta:1
							})},1000)
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			mplaygamejifen(){
				let token = uni.getStorageSync("token")
				uni.request({
					url: this.G_base + '/api/lz/mfqyxstart',
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + token
					},
					data:{
						qid:this.qid,
						status:2
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==200){
							uni.showToast({
								title:"开通成功"
							})
							setTimeout(()=>{uni.navigateBack({
								delta:1
							})},1000)
						}
					},
					fail: (err) => {
						console.log(err)
					}
				});
			},
			// playgame(){
			// 	uni.navigateTo({
			// 		url:"../chuangqun/chuangqun?qid="+this.qid+"&status="+1+'&roomid='+this.roomid+'&groupName='+this.groupName
					
			// 	})
			// },
			playgamejifen(){
				uni.navigateTo({
					url:"../chuanqun/chuanqun?qid="+this.qid+"&status="+1+'&roomid='+this.roomid+'&jifen='+1+'&groupName='+this.groupName
					
				})
			},
			xufei(){
				uni.navigateTo({
					url:"../chuanqun/chuanqun?qid="+this.qid+"&status="+2+'&roomid='+this.roomid+'&groupName='+this.groupName
				})
			},
			test() {
				uni.navigateBack({
					delta: 1
				})
			},
			jinqiangmailei(){
				
				if(this.guize.sjinfo.hour==0&&this.guize.sjinfo.min==0&&this.guize.sjinfo.sec==0){
					uni.showToast({
						title:"请先开通",
						icon:"none"
					})
					return
				}
				if(this.status==1){ 
					uni.showToast({
						title:"本群为禁枪埋雷群",
						icon:"none"
					})
					return
				}
				uni.navigateTo({
					url:"/pages/gametwo?roomid="+this.roomid+'&groupName='+this.groupName
				})
			}
		}
	}
</script>

<style scoped>
	.zjl_header {
		text-align: center;
	}

	.zjl_header button {
		margin-top: 15px;
		border-radius: 30px;
	}
	
	.zjl_hedn {
		display: flex;
		justify-content: space-around;
		padding: 10px;
		text-align: center;
		margin-top: 25px;
	}

	.zjl_hedn image {
		width: 60px;
		height: 60px;
	}

	.zjl_hedn view {
		margin-top: 10px;
	}
</style>
